package com.itheima.manager;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.UmsMenu;
import com.itheima.service.db.UmsMenuService;
import com.itheima.util.R;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

@Component
public class UmsMenuManager {


    @DubboReference
    UmsMenuService umsMenuService;


    public R getByCondictions(Integer parentId, Integer pageNum, Integer pageSize) {
        Page<UmsMenu> page=umsMenuService.findByParentId(parentId,pageNum,pageSize);
        return R.success(new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords()));
    }

    public R selectById(Integer id) {
        return R.success(umsMenuService.findById(id.longValue()));
    }

    public R selectMenuList() {
        return R.success(umsMenuService.selectMenuList());
    }

    public R addMenu(UmsMenu umsMenu) {
        umsMenuService.save(umsMenu);
        return R.success("");
    }

    public R deleteMenu(Integer id) {
        Boolean delete = umsMenuService.delete(id);
        return delete?R.success(""):R.error(500,"请先删除子级菜单");
    }

    public R updateMenuStatu(Integer id, Integer hidden) {
        umsMenuService.updateMenuStatu(id,hidden);
        return R.success("");
    }

    public R updateMenu(Integer id, UmsMenu umsMenu) {
        umsMenuService.updateMenu(id,umsMenu);
        return R.success("");
    }
}
